﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Physis.Client.Controllers {

    public class HomeController : ApplicationController {

        public ActionResult Index() {

            if (applicationModel.Application.Session == null) { return null; }

            return View("~/Views/Home/HomeIndex.cshtml", new Models.ApplicationModel ());

        }

        public JsonResult ConfigurationObjectsAvailable (String objectType) {

            JsonResponses.jqGridDataResponse response = new JsonResponses.jqGridDataResponse (Request.QueryString);


            switch (objectType.ToLower ()) {

                case "securityauthority":

                    List<Security.SecurityAuthority> securityAuthorities = applicationModel.Application.Security.SecurityAuthorities ();

                    response.RowsByPage (securityAuthorities);

                    break;

                case "environment":

                    List<Enterprise.Environment> environments = applicationModel.Application.Enterprise.Environments ();

                    response.RowsByPage (environments);

                    break;

                case "enterpriserole":

                    List<Security.Role> enterpriseRoles = applicationModel.Application.Security.RolesByEnvironment (0);

                    response.RowsByPage (enterpriseRoles);

                    break;

                case "environmentrole":

                    List<Security.Role> environmentRoles = applicationModel.Application.Security.Roles (false);

                    environmentRoles = environmentRoles.FindAll (role => role.EnvironmentId != 0).ToList ();

                    response.RowsByPage (environmentRoles);

                    break;

                case "useraccount":

                    List<Security.UserAccount> userAccounts = applicationModel.Application.Security.UserAccounts ();

                    response.RowsByPage (userAccounts);

                    break;

            }



            return Json (response, JsonRequestBehavior.AllowGet);

        }

    }

}
